/**
 * @file
 * @author
 * @date
 * @brief 显示模块
 */
#include "display_ctrl.h"
#include "display_drv.h"
//#include "display_sub_r30.h"
#include "app_timer.h"

//#include "oled.h"
#include "sports_mode.h"
#include "string.h"
//#include "gnss_ctrl.h"
#include "app_trace.h"
#include "heart_rate_interface.h"
#include "m_product_test.h"
#include "view.h"
#include "weather_ctrl.h"
#ifdef USE_TOUCHPAD
#include "touchpad.h"
#endif                     //!<#ifdef USE_TOUCHPAD
#define DISP_LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)
// #define DISP_LOG(fmt, ...)
#define DISP_MOVE_UP_DOWN_FAST (1)
// #define DISP_MOVE_UP_DOWN_SPEED_MS (220 / (OLED_SIZE_Y / DISPLAY_AREA_LINES)) //滚动速度控制

disp_ctrl_t disp_ctrl; //显示控制结构体

APP_TIMER_DEF(disp_drv_timer_id);

// static uint32_t move_up_down_last_time;
/*********************************************************************************************
 * @brief 显示模块驱动定时器,标记显示驱动节奏
 ********************************************************************************************/
static void disp_drv_time_handle(void *p_context)
{
    disp_ctrl.timer_flag++;
}

/*********************************************************************************************
 * @brief 正常刷新显示
 * @warning
 ********************************************************************************************/
void disp_update_mode_normal(void)
{
    // DISP_LOG("disp_update_mode_normal");
    if (disp_ctrl.area_update_flag == 0) //全屏刷新
    {
        disp_ctrl.area_start_x = 0;
        disp_ctrl.area_end_x = OLED_SIZE_X - 1;
        disp_ctrl.area_start_y = 0;
        disp_ctrl.area_end_y = disp_ctrl.area_start_y + DISPLAY_AREA_LINES - 1;
        lcd_set_xy(0, OLED_SIZE_X - 1, (disp_ctrl.last_y_offset + disp_ctrl.area_start_y) % OLED_RAM_Y_MAX, OLED_RAM_Y_MAX - 1);
        for (disp_ctrl.loop_cnt = 0; disp_ctrl.area_start_y <= (OLED_SIZE_Y - 1); disp_ctrl.loop_cnt++)
        {
            memset(disp_ctrl.disp_buff[disp_ctrl.p_buff_flag], 0, sizeof(disp_ctrl.disp_buff[0]));
            view_display();
            if ((disp_ctrl.last_y_offset + disp_ctrl.area_start_y) % OLED_RAM_Y_MAX == 0)
            {
                lcd_set_xy(0, OLED_SIZE_X - 1, 0, OLED_RAM_Y_MAX - 1);
            }
            oled_fill_data_continue(OLED_SIZE_X, DISPLAY_AREA_LINES, (const uint8_t *)disp_ctrl.disp_buff[disp_ctrl.p_buff_flag]);
            disp_ctrl.p_buff_flag ^= 1;
            disp_ctrl.area_start_y += DISPLAY_AREA_LINES;
            disp_ctrl.area_end_y += DISPLAY_AREA_LINES;
        }
    }
    else //局部刷新
    {
        uint8_t x_width = disp_ctrl.area_update_end_x - disp_ctrl.area_update_start_x + 1;
        disp_ctrl.area_start_x = disp_ctrl.area_update_start_x;
        disp_ctrl.area_end_x = disp_ctrl.area_update_end_x;
        disp_ctrl.area_start_y = disp_ctrl.area_update_start_y;
        disp_ctrl.area_end_y = disp_ctrl.area_start_y + DISPLAY_AREA_LINES - 1;
        int16_t end_y = disp_ctrl.area_update_end_y;
        if ((disp_ctrl.area_end_x == (OLED_SIZE_X - 1)) && (disp_ctrl.area_start_x == 0))
        {
            lcd_set_xy(0, OLED_SIZE_X - 1, (disp_ctrl.last_y_offset + disp_ctrl.area_start_y) % OLED_RAM_Y_MAX, OLED_RAM_Y_MAX - 1);
        }
        for (disp_ctrl.loop_cnt = 0; disp_ctrl.area_start_y <= end_y; disp_ctrl.loop_cnt++)
        {
            memset(disp_ctrl.disp_buff[disp_ctrl.p_buff_flag], 0, sizeof(disp_ctrl.disp_buff[0]));
            view_display();
            if ((disp_ctrl.last_y_offset + disp_ctrl.area_start_y) % OLED_RAM_Y_MAX == 0)
            {
                lcd_set_xy(0, OLED_SIZE_X - 1, 0, OLED_RAM_Y_MAX - 1);
            }
            uint8_t draw_y_lines = (end_y - disp_ctrl.area_start_y + 1) > DISPLAY_AREA_LINES ? DISPLAY_AREA_LINES : (end_y - disp_ctrl.area_start_y + 1);
            if (x_width == OLED_SIZE_X)
            {
                oled_fill_data_continue(OLED_SIZE_X, draw_y_lines, (const uint8_t *)disp_ctrl.disp_buff[disp_ctrl.p_buff_flag]);
            }
            else
            {
                const uint8_t *p_disp_buff = (const uint8_t *)disp_ctrl.disp_buff[disp_ctrl.p_buff_flag] + disp_ctrl.area_start_x * 2;
                for (uint8_t i = 0; i < draw_y_lines; i++)
                {
                    oled_fill_data(disp_ctrl.area_start_x, (disp_ctrl.last_y_offset + disp_ctrl.area_start_y + i) % OLED_RAM_Y_MAX, x_width, 1, p_disp_buff);
                    p_disp_buff += OLED_SIZE_X * 2;
                }
            }
            disp_ctrl.p_buff_flag ^= 1;
            disp_ctrl.area_start_y += DISPLAY_AREA_LINES;
            disp_ctrl.area_end_y += DISPLAY_AREA_LINES;
        }
    }
}

/*********************************************************************************************
 * @brief 滚动显示实现
 * @warning
 ********************************************************************************************/
void disp_update_mode_up_move(void)
{
    DISP_LOG("%u move up", get_ms());
    disp_ctrl.area_start_x = 0;
    disp_ctrl.area_end_x = OLED_SIZE_X - 1;
    disp_ctrl.area_start_y = 0;
    disp_ctrl.area_end_y = DISPLAY_AREA_LINES - 1;

    for (disp_ctrl.loop_cnt = 0; disp_ctrl.loop_cnt < OLED_SIZE_Y / DISPLAY_AREA_LINES; disp_ctrl.loop_cnt++)
    {
        memset(disp_ctrl.disp_buff[disp_ctrl.p_buff_flag], 0, sizeof(disp_ctrl.disp_buff[0]));
        view_display();
        lcd_set_ram_offset(disp_ctrl.last_y_offset);
#if 1

#else
        uint32_t temp32;
        app_timer_cnt_get(&temp32);
        while ((temp32 - move_up_down_last_time) < DISP_MOVE_UP_DOWN_SPEED_MS * 32768 / 1000)
        {
            app_timer_cnt_get(&temp32);
        }

        move_up_down_last_time = temp32;
#endif
        oled_fill_data(0, (disp_ctrl.last_y_offset + OLED_SIZE_Y) % OLED_RAM_Y_MAX, OLED_SIZE_X, DISPLAY_AREA_LINES, (const uint8_t *)disp_ctrl.disp_buff[disp_ctrl.p_buff_flag]);
        disp_ctrl.p_buff_flag ^= 1;
        disp_ctrl.last_y_offset += DISPLAY_AREA_LINES;
        disp_ctrl.last_y_offset = disp_ctrl.last_y_offset % OLED_RAM_Y_MAX;
        disp_ctrl.area_start_y += DISPLAY_AREA_LINES;
        disp_ctrl.area_end_y += DISPLAY_AREA_LINES;
    }
    lcd_set_ram_offset(disp_ctrl.last_y_offset);
}

/*********************************************************************************************
 * @brief 滚动显示实现
 * @warning
 ********************************************************************************************/
void disp_update_mode_down_move(void)
{
    // DISP_LOG("%u move down", get_ms());
    disp_ctrl.area_start_x = 0;
    disp_ctrl.area_end_x = OLED_SIZE_X - 1;
    disp_ctrl.area_start_y = OLED_SIZE_Y - DISPLAY_AREA_LINES;
    disp_ctrl.area_end_y = OLED_SIZE_Y - 1;
    for (disp_ctrl.loop_cnt = 0; disp_ctrl.loop_cnt < OLED_SIZE_Y / DISPLAY_AREA_LINES; disp_ctrl.loop_cnt++)
    {
        memset(disp_ctrl.disp_buff[disp_ctrl.p_buff_flag], 0, sizeof(disp_ctrl.disp_buff[0]));
        view_display();
        lcd_set_ram_offset(disp_ctrl.last_y_offset);
#if 1

#else
        uint32_t temp32;
        app_timer_cnt_get(&temp32);

        while ((temp32 - move_up_down_last_time) < DISP_MOVE_UP_DOWN_SPEED_MS * 32768 / 1000)
        {
            app_timer_cnt_get(&temp32);
        }

        move_up_down_last_time = temp32;
#endif
        oled_fill_data(0, (disp_ctrl.last_y_offset + OLED_RAM_Y_MAX - DISPLAY_AREA_LINES) % OLED_RAM_Y_MAX, OLED_SIZE_X, DISPLAY_AREA_LINES,
                       (const uint8_t *)disp_ctrl.disp_buff[disp_ctrl.p_buff_flag]);
        disp_ctrl.p_buff_flag ^= 1;
        if (disp_ctrl.last_y_offset >= DISPLAY_AREA_LINES)
        {
            disp_ctrl.last_y_offset -= DISPLAY_AREA_LINES;
        }
        else
        {
            disp_ctrl.last_y_offset = OLED_RAM_Y_MAX - DISPLAY_AREA_LINES;
        }
        disp_ctrl.area_start_y -= DISPLAY_AREA_LINES;
        disp_ctrl.area_end_y -= DISPLAY_AREA_LINES;
    }
    lcd_set_ram_offset(disp_ctrl.last_y_offset);
}
/*********************************************************************************************
 * @brief 直接结束显示的循环
 * @param [in] param1
 * @param [out] param2
 * @return ret
 * @note
 * @warning
 ********************************************************************************************/
void disp_update_set_loop_end(void)
{
    disp_ctrl.loop_cnt = OLED_SIZE_Y / DISPLAY_AREA_LINES;
    disp_ctrl.area_start_y = OLED_SIZE_Y;
}

/*********************************************************************************************
 * @brief
 * @param [in] param1
 * @param [out] param2
 * @return ret
 * @note
 * @warning
 ********************************************************************************************/
void disp_update_to_lcd(void)
{
// DISP_LOG("disp_update_to_lcd");
#ifdef DISPLAY_MODE_NORMAL_ONLY
    disp_update_mode_normal();
#else
    switch (disp_ctrl.mode)
    {
    case DISP_MODE_NORMAL:
        disp_update_mode_normal();
        break;
    case DISP_MODE_UP_MOVE:
        disp_update_mode_down_move();
        break;
    case DISP_MODE_DOWN_MOVE:
        disp_update_mode_up_move();
        break;
    default:
        disp_update_mode_normal();
        break;
    }
#endif
    disp_ctrl.auto_refresh_time_temp = disp_ctrl.auto_refresh_time;
    //关闭打开的文件
    // DISP_LOG("ready close");
    for (int i = 0; i < DISP_LFS_FILE_USE_MAX; i++)
    {
        if (disp_ctrl.common_file[i].flags != 0)
        {
            // DISP_LOG("close file %d", i);
            lfs_file_close(&little_fs, &disp_ctrl.common_file[i]);
            memset(&disp_ctrl.common_file[i], 0, sizeof(disp_ctrl.common_file[0]));
        }
    }
}

/*********************************************************************************************
 * @brief 设置自动刷新的区域
 * @warning
 ********************************************************************************************/
void display_set_update_area(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
    disp_ctrl.area_update_start_x = x;
    disp_ctrl.area_update_start_y = y;
    disp_ctrl.area_update_end_x = x + width - 1;
    disp_ctrl.area_update_end_y = y + height - 1;
    disp_ctrl.area_update_flag = 1;
}

/*********************************************************************************************
 * @brief 界面切换
 * @warning
 ********************************************************************************************/
static void disp_type_switch(void)
{
    if (disp_ctrl.new_disp_type)
    {
        if (disp_ctrl.new_disp_type != disp_ctrl.current_disp_type)
        {
            event_param_t exit_param = {
                .source = event_source_system,
                .event = event_view_exit,
                .next_view = disp_ctrl.new_disp_type,
            };
            // DISP_LOG("exit view = %d", disp_ctrl.current_disp_type);
            view_event(exit_param);
        }

        int previous_view = disp_ctrl.current_disp_type;
        disp_ctrl.current_disp_type = disp_ctrl.new_disp_type;

        disp_ctrl.new_disp_type = view_empty;
        disp_ctrl.mode = disp_ctrl.new_mode;
        if (disp_ctrl.current_disp_type == DISP_TYPE_CLOSE_OLED) //息屏直接跳过
        {
            // disp_ctrl.on = DISP_ON_DISABLE;
            disp_ctrl.auto_close_delay = 1;
        }
        else
        {
            bool event_re_screen_on = false;
            //关屏启动时启动定时器
            if (disp_ctrl.on == DISP_ON_DISABLE)
            {
                app_timer_start(disp_drv_timer_id, APP_TIMER_TICKS(DISP_DRV_TIME_INTERVAL, APP_TIMER_PRESCALER), NULL);
                disp_ctrl.on = DISP_ON_UPDATE_FROM_OFF;
                oled_turn_on(); //打开显示
                DISP_LOG("disp timer on");
                event_re_screen_on = true;
            }
            else
            {
                disp_ctrl.on = DISP_ON_UPDATE;
            }
            //界面切换处理
            if (previous_view != disp_ctrl.current_disp_type)
            {
                disp_ctrl.auto_refresh_count = 0;
                disp_ctrl.auto_refresh_time = 32000;
                disp_ctrl.oled_ram_disable_auto_update = 0; //界面切换后自动打开更新
            }
            disp_ctrl.auto_close_delay = DISP_CLOSE_TIME_DEFAULT; //设置默认息屏时间，不同case如果要修改持续时间在后面修改即可
            if (event_re_screen_on)
            {
                event_param_t entry_param = {
                    .source = event_source_system,
                    .event = event_view_re_screen_on,
                };
                // DISP_LOG("entry view = %d", disp_ctrl.current_disp_type);
                view_event(entry_param);
            }
        }
        disp_ctrl.timer_flag = 1;       //置标记位，立即执行显示
        disp_ctrl.area_update_flag = 0; //重置局部刷新标记，全屏刷新
        if (previous_view != disp_ctrl.current_disp_type)
        {
            event_param_t entry_param = {
                .source = event_source_system,
                .event = event_view_entry,
                .previous_view = previous_view,
            };
            // DISP_LOG("entry view = %d", disp_ctrl.current_disp_type);
            view_event(entry_param);
        }
    }
}

/********************************************************************************************
 * @brief 显示驱动，在主循环调用
 * @note
 * @warning
 ********************************************************************************************/
void display_drv_process(void)
{

    disp_type_switch(); //处理界面切换
    // DISP_LOG("disp_type_switch end");
    //显示界面
    if (disp_ctrl.timer_flag)
    {
        uint8_t timer_flag_cnt = disp_ctrl.timer_flag;
        disp_ctrl.timer_flag = 0;

        //处理显示更新
        if (disp_ctrl.on == DISP_ON_UPDATE) //移动刷新
        {
            disp_ctrl.auto_refresh_count = 0;
            disp_ctrl.area_update_flag = 0; //重置局部刷新标记，全屏刷新
            disp_update_to_lcd();           //全屏50ms左右
            disp_ctrl.on = DISP_ON_STANDBY;
            disp_ctrl.mode = DISP_MODE_NORMAL;
        }
        else if (disp_ctrl.on == DISP_ON_UPDATE_FROM_OFF) //息屏状态下起来
        {
            disp_update_to_lcd(); //全屏50ms左右
            disp_ctrl.on = DISP_ON_STANDBY;
            disp_ctrl.mode = DISP_MODE_NORMAL;
            DISP_LOG("peripheral_oledpower_On");
#if 0 // defined(R911_V1_11_BOARD)
            extern void oled_display_on(void);
            oled_display_on();
#else
            peripheral_oledpower_On(); //开背光
#endif
#ifdef USE_TOUCHPAD
            touchpad_screen_on();
#endif
        }
        else if (disp_ctrl.on == DISP_ON_STANDBY) //常态刷新显示
        {
            disp_ctrl.auto_refresh_time_temp -= (DISP_DRV_TIME_INTERVAL * timer_flag_cnt);
            if (disp_ctrl.auto_refresh_time_temp <= 0) //更新显示
            {
                // DISP_LOG("refresh auto_refresh_time=%d count= %d", disp_ctrl.auto_refresh_time, disp_ctrl.auto_refresh_count);
                disp_ctrl.auto_refresh_time_temp = disp_ctrl.auto_refresh_time;
                disp_ctrl.auto_refresh_count++;
                // disp_func_set_interface(); //更新显示BUFF
                if (disp_ctrl.oled_ram_disable_auto_update == 0)
                {
                    // DISP_LOG("DISP_ON_STANDBY");
                    disp_update_to_lcd();
                }
            }
        }
#if 0
#warning debug
        disp_ctrl.auto_close_delay = 5000;
#endif
        //自动息屏时间
        if (disp_ctrl.auto_close_delay > 0)
        {
            disp_ctrl.auto_close_delay -= (DISP_DRV_TIME_INTERVAL * timer_flag_cnt);
            disp_ctrl.auto_back_to_time = 0;
        }
        if (disp_ctrl.auto_close_delay <= 0)
        {
            if (disp_ctrl.auto_back_to_time == 0)
            {
                DISP_LOG("screen power off");
                peripheral_oledpower_Off(); //先灭背光
#ifdef USE_TOUCHPAD
                touchpad_screen_off();
#endif
                disp_ctrl.on = DISP_ON_DISABLE;
                oled_all_fill_data(0);
                oled_turn_off();
                if (disp_ctrl.current_disp_type == DISP_TYPE_CLOSE_OLED)
                {
                    disp_ctrl.auto_back_to_time = 1;
                }
                else
                {
                    disp_ctrl.auto_back_to_time = 5000;
                }
            }
            else
            {
                disp_ctrl.auto_back_to_time -= (DISP_DRV_TIME_INTERVAL * timer_flag_cnt);
                if (disp_ctrl.auto_back_to_time <= 0)
                {
                    disp_ctrl.timer_flag = 0;
                    bool is_exit_to_empty = is_view_exit_to_empty(disp_ctrl.current_disp_type);
                    if (is_exit_to_empty)
                    {
                        event_param_t exit_param = {
                            .source = event_source_system,
                            .event = event_view_exit,
                            .next_view = view_empty,
                        };
                        DISP_LOG("exit view = %d", disp_ctrl.current_disp_type);
                        view_event(exit_param);
                        DISP_LOG("entry empty screen");
                        disp_ctrl.current_disp_type = view_empty;
                        disp_ctrl.disp_type_back = view_time;
                    }

                    app_timer_stop(disp_drv_timer_id);
                    disp_ctrl.auto_back_to_time = 0;
                }
            }
        }
    }
}

/*********************************************************************************************
 * @brief 查询当前的状态
 * @warning
 ********************************************************************************************/
disp_type_t display_get_present_type(void)
{
    if (disp_ctrl.new_disp_type)
    {
        return disp_ctrl.new_disp_type; //如果已经存在状态切换请求，以新的状态为准
    }
    else
    {
        return disp_ctrl.current_disp_type;
    }
}

/*********************************************************************************************
 * @brief 备份显示状态
 * @warning
 ********************************************************************************************/
void display_set_disp_type_backup(void)
{
    int view = display_get_present_type();
    if (display_get_present_type() < view_normal_end && display_get_present_type() >= view_normal_start)
    {
        disp_ctrl.disp_type_back = display_get_present_type();
        // disp_ctrl.disp_type_sub_back = disp_ctrl.disp_type_sub;
    }
}

/*********************************************************************************************
 * @brief 恢复备份的显示状态
 * @warning
 ********************************************************************************************/
void display_show_type_recover(void)
{
    if (disp_ctrl.disp_type_back != view_empty)
    {
        display_show(disp_ctrl.disp_type_back, DISP_MODE_NORMAL);
        disp_ctrl.disp_type_back = view_empty;
    }
    else
    {
        display_show(view_time, DISP_MODE_NORMAL);
    }
}

/*********************************************************************************************
 * @brief 对外显示接口
 * @param [in] mode @ disp_mode_t
 * @note
 * @warning
 ********************************************************************************************/
void display_show(disp_type_t disp_type, disp_mode_t mode)
{
    if (DeviceState.PowerState == POWEROFFOK && disp_type != view_prompt_charing && disp_type != view_close_oled)
    {
        return;
    }
    if (view_not_used == disp_type)
    {
        return;
    }
    if (disp_type == view_close_oled && disp_ctrl.current_disp_type == view_empty)
    {
        DISP_LOG("already close");
        return;
    }
    display_set_disp_type_backup();

    if (disp_type == view_empty)
    {
        disp_type = view_time;
    }
    if (disp_type == view_time)
    {
        product_test_state_t state = product_test_state_get();
        switch (state)
        {
        case PRODUCT_TEST_STATE_TEST_NONE:
            display_show(view_untested, DISP_MODE_NORMAL);
            return;
        case PRODUCT_TEST_STATE_TEST_PCBA:
            display_show(view_finished_product_start, DISP_MODE_NORMAL);
            return;
        }
    }
    disp_ctrl.new_disp_type = disp_type;

    if (mode > DISP_MODE_DOWN_MOVE) //暂不支持其它刷屏方式，默认为普通
    {
        disp_ctrl.new_mode = DISP_MODE_NORMAL;
    }
    else
    {
        disp_ctrl.new_mode = mode;
    }
}
/*********************************************************************************************
 * @brief 用来更新显示，比如蓝牙状态改变等需要更新界面的时候
 * @param [in] valid_disp_type 有效的显示状态，只有当前是此状态时才刷新
 * @param [out] level 刷新程度等级
 * @warning
 ********************************************************************************************/
void display_set_update_request(disp_type_t valid_disp_type, uint8_t level)
{
    DISP_LOG("display_set_update_request= %d", valid_disp_type);
    if (disp_ctrl.current_disp_type == valid_disp_type)
    {
        disp_ctrl.oled_update_need = 1; //重新刷新一次
        if (disp_ctrl.on == DISP_ON_STANDBY)
        {
            disp_ctrl.on = DISP_ON_UPDATE;
            disp_ctrl.mode = DISP_MODE_NORMAL;
        }
    }
}

/*********************************************************************************************
 * @brief 设置自动息屏的时间
 * @param [in] delay_ms 有效的显示状态，只有当前是此状态时才刷新
 * @param [out] level 刷新程度等级
 * @warning
 ********************************************************************************************/
void display_set_auto_close_time(uint32_t delay_ms)
{
    disp_ctrl.auto_close_delay = delay_ms;
}

static void oled_power_pin_init(void)
{
#ifdef USE_IO_DRIVER_OLED
    NRF_GPIO_OUTPUT_H1(OLED_POWER_PIN);
#if (defined(OLED_POWER_PIN_NUM) && OLED_POWER_PIN_NUM >= 2)
    NRF_GPIO_OUTPUT_H1(OLED_POWER_2_PIN);
#endif //!<#if (defined(OLED_POWER_PIN_NUM) && OLED_POWER_PIN_NUM >= 2)
#else //!< #ifdef USE_IO_DRIVER_OLED
    nrf_gpio_cfg_output(OLED_POWER_PIN);
#if (defined(OLED_POWER_PIN_NUM) && OLED_POWER_PIN_NUM >= 2)
    nrf_gpio_cfg_output(OLED_POWER_2_PIN);
#endif //!<#if (defined(OLED_POWER_PIN_NUM) && OLED_POWER_PIN_NUM >= 2)
#endif //!< #ifdef USE_IO_DRIVER_OLED
}
/*********************************************************************************************
 * @brief 显示模块初始化
 * @note
 * @warning
 ********************************************************************************************/
void display_ctrl_init(void)
{
    oled_power_pin_init();
#if 0
#warning debug
    peripheral_oledpower_Off();
    peripheral_oledpower_On();
    peripheral_oledpower_Off();
    peripheral_oledpower_On();
#endif
#if USE_OLED_RESET
    nrf_gpio_cfg_output(OLED_RESET_PIN);
#endif
    lcd_drv_init();
    oled_turn_off();
    memset(&disp_ctrl, 0, sizeof(disp_ctrl));
    uint32_t err_code = app_timer_create(&disp_drv_timer_id, APP_TIMER_MODE_REPEATED, disp_drv_time_handle);
    APP_ERROR_CHECK(err_code);

    // peripheral_oledpower_Off(); //灭背光
}
